<?php
/*========================================= JooSam =========================================/
/																							/
/	Extention:		JooSam																	/
/	Created by:		Broadcastweb.eu - Paules												/
/	Site:			http://www.broadcastweb.eu												/
/	Email:			support@broadcastweb.eu													/
/	Copyright:		2011 - 2012 (c) Broadcastweb.eu											/
/	License:		CC BY-NC-ND 3.0 ~ http://creativecommons.org/licenses/by-nc-nd/3.0/		/
/	File Version:	0003																	/
/																							/
/========================================== JooSam ========================================*/
// Joomla security
defined('_JEXEC') or die;
jimport('joomla.application.component.modellist');

class JoosamModelSamsongs extends JModelList{
	
	// Get SQL Data
	public function samSonglist(){
		require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_joosam' . DS . 'helpers' . DS . 'helper.samdb.php';
		$EditServer = JoosamHelper::currSrvEdit();
		$data = SamdbHelper::samdb('getSonglist', $EditServer['id']);
		$data = $data['data'];
		return $data;
	}

	public function __construct(){
 		parent::__construct();
 
		$mainframe = JFactory::getApplication();
 
		// Get pagination request variables
		$limit = $mainframe->getUserStateFromRequest('global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int');
		$limitstart = JRequest::getVar('limitstart', 0, '', 'int');
 
		// In case limit has been changed, adjust it
		$limitstart = ($limit != 0 ? (floor($limitstart / $limit) * $limit) : 0);
 
		$this->setState('limit', $limit);
		$this->setState('limitstart', $limitstart);
	}

	public function getTotal(){

		require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_joosam' . DS . 'helpers' . DS . 'helper.samdb.php';
		$EditServer = JoosamHelper::currSrvEdit();
		$data = SamdbHelper::samdb('countSonglist', $EditServer['id']);

 		// Load the content if it doesn't already exist
 		if(empty($this->_total)){
 			$this->_total = $data['data'];	
 		}
 		return $this->_total;
	}

	public function getPagination(){
 		// Load the content if it doesn't already exist
 		if (empty($this->_pagination)) {
 			jimport('joomla.html.pagination');
 			$this->_pagination = new JPagination($this->getTotal(), $this->getState('limitstart'), $this->getState('limit') );
 		}
 		return $this->_pagination;
	}
}